//////////////////////////////////////////////////////////////////////
//////////////////Global Java Script Function/////////////////////////
//////////////////////////////////////////////////////////////////////
function trim(STRING)
{
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING)
{
	while(STRING.charAt((STRING.length -1))==" ")
	{
	 STRING = STRING.substring(0,STRING.length-1);
	}
return STRING;
}

function LTrim(STRING)
{
	while(STRING.charAt(0)==" "){
	STRING = STRING.replace(STRING.charAt(0),"");
	}
return STRING;
}
function check_date()
{
	fromDate = parseInt(document.frm.year1.value+document.frm.month1.value+document.frm.day1.value)
	toDate = parseInt(document.frm.year2.value+document.frm.month2.value+document.frm.day2.value)
	if(fromDate > toDate)
	{
		alert("From date can not greater than to date.");
		return false;
	}
}

function checkBlank(str)
{
	if(str=="")
		return 1;
	else
		return 0;
}
function checkSpecialChars(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					//if (iChars.indexOf(form['first_name'].value.charAt(i)) != -1) {
					//alert ("First Name has special characters. \nThese are not allowed.\n");
					//alert ("Only characters are allowed in First Name ");
					 //form['first_name'].focus();
					return false;
		  }
	}
	return true;
}
function checkAlphaNumeric(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					//if (iChars.indexOf(form['first_name'].value.charAt(i)) != -1) {
					//alert ("First Name has special characters. \nThese are not allowed.\n");
					//alert ("Only characters are allowed in First Name ");
					 //form['first_name'].focus();
					return false;
		  }
	}
	return true;
}
function checkDescription(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,-/\()-_!@#%^&*?<>` ";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					//if (iChars.indexOf(form['first_name'].value.charAt(i)) != -1) {
					//alert ("First Name has special characters. \nThese are not allowed.\n");
					//alert ("Only characters are allowed in First Name ");
					 //form['first_name'].focus();
					return false;
		  }
	}
	return true;
}
function checkAccountNo(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					//if (iChars.indexOf(form['first_name'].value.charAt(i)) != -1) {
					//alert ("First Name has special characters. \nThese are not allowed.\n");
					//alert ("Only characters are allowed in First Name ");
					 //form['first_name'].focus();
					return false;
		  }
	}
	return true;
}
function checkProgramme(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-@!#$%^&*()+=[]{} ";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					
					return false;
		  }
	}
	return true;
}
function checkCompany(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@_&-. ";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					//if (iChars.indexOf(form['first_name'].value.charAt(i)) != -1) {
					//alert ("First Name has special characters. \nThese are not allowed.\n");
					//alert ("Only characters are allowed in First Name ");
					 //form['first_name'].focus();
					return false;
		  }
	}
	return true;
}
function checkUser(str)
{
	var iChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					
					return false;
		  }
	}
	return true;
}
function checkMoney(str)
{
	var iChars = "0123456789.0";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					
					return false;
		  }
	}
	return true;
}
function checkPhone(str)
{ 
      var regex = /^([0-9]{11})$/; 
      var regex1 = /^([0-9]{10})$/;             
      if(!regex.test(str) && !regex1.test(str))
	  {
			 return false;
      }
	  if(str == '0000000000' || str == '00000000000')
	  {
			 return false;
      }
	  return true;
}

function checkEmail(str)
{
       var regex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
       if(!regex.test(str))
	   {
          return false;
       }
return true;
}

function checkWebsite(str)
{
	var ext = str.substring(0,7);
	if(ext == 'http://')
	{
		url = str.substring(7,str.length);
		if(!checkUrl(url))
		{
			return false;
		}
	}
	else
	{	
		var iChars = "!@#$%^&*()+=[]';,{}|\"<>? ";
        for (var i = 0; i < str.length; i++)
		{
                
				if (iChars.indexOf(str.charAt(i)) != -1) 
				{
                   return false;
				}
         }
	}
	return true;
}
function checkNumeric(str)
{
	var iChars = "0123456789";
	for (var i = 0; i < str.length; i++)
	{
		 if (iChars.indexOf(str.charAt(i)) == -1) 
		 {
					
					return false;
		  }
	}
	return true;
}

function checkURLMain(str)
{
	var ext = str.substring(0,7);
	if(ext == 'http://')
	{
		url = str.substring(7,str.length);
		var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}[A-Za-z0-9-_]{1}([\w]+)(.[\w]+){1,2}$/;
		if(urlRegxp.test(str) != true)
		{
			alert("Please Enter Valid Site Url");
			return false;
		}
		else if(!checkUrl(url))
		{
			return false;
		}
	}
	else
	{	
		alert("Please Enter URL with http://www.");
		return false;
	}
	return true;
}
function checkUrl(nname)
{
var arr = new Array(
'.com','.net','.org','.biz','.coop','.info','.museum','.name',
'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
'.wf','.ye','.yt','.yu','.za','.zm','.zw');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your url extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 alert("URL name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your URL name should not have special characters");
			 return false;
		  }
		}
	}
}
else
{
 alert("Your URL name is too short/long");
 return false;
}	

return true;
}

/////////////////////////////////////////////////////////////////////////
//////////////////////Tool Tip Function/////////////////////////////////
///////////////////////////////////////////////////////////////////////
// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety =  8;

function newelement(newid)
{ 
    
																				 
	if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip)
{
    var msgArray = new Array;
	msgArray[0] = "First Name should not be numeric([1-9]) or special characters(*&^!@#...) or blank. Example:Jhon.";
	msgArray[1] = "Last Name should not be numeric([1-9]) or special characters(*&^!@#...). Example:  Hilton.";
	msgArray[2] = "Contact No. should not have any character or space between digits and it can not be blank. It may be a numeric number having 10 digit or 11 digit number. Example: 0123456789 or 01234567890";
	msgArray[3] = "Fax No. should not have any character or space between digits. It may be a numeric number having 10 digit or 11 digit number. Example: 0123456789 or 01234567890";
	msgArray[4] = "Email Address should not have special character and space and it can not be blank. It can be a alphanumeric  having '_' ,'@' is valid. Example: abc@epurple.co.uk";   
	msgArray[5] = "Company Name can be any string.It can not be blank. Example: Epurple Media Ltd";
	msgArray[6] = "Address can be any alpha numeric string like c-73 street london, uk. It can not be blank"; 
	msgArray[7] = "Site Url can be like that http://www.epurple.co.uk";
	msgArray[8] = "User can be any more than 6 character alphanumeic string with only special character('-' ,'_') allowed and space between string can not be allowed. It can not be blank."; 
	msgArray[9] = "Password can be any more than 6 character alphanumeic string with only special character('-','_') allowed and  space between string can not be allowed. It can not be blank."; 
	msgArray[10] = "Verify Password can be any more than 6 character alphanumeic string with only special character('-','_') allowed and  space between string can not be allowed. It can not be blank."; 
	msgArray[11] = "Website can be any valid website name like epurplemedia.co.uk or epuplemedia. It can not be blank."
	msgArray[12] = "Specify your description.."
	msgArray[13] = "Only jpg, gif and png images of size('468X60','62X62','60X30','60X300','120X600','120X60','215X119') can be uploaded";
	msgArray[14] = "Tracking URL should be a valid link like http://www.epurplemedia.co.uk/trackURL.php.";
	if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
    tip = msgArray[tip]
	lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}

///////////////////Tool Tip Function/////////////////////////////////
////////////////////////////////////////////////////////////////////

/////////////////Global Java Script Function//////////////////////////
/////////////////Developed by suyash dt.15/01/2007////////////////////
////////////////////////////////////////////////////////////////


////java script valiadtion for subscriber section//////////////
/////////////////by suyash///////////////////////////////////
function frmValidate()
{
	
	if(checkBlank(document.frm.email.value))
	{
		alert("Please Enter Email");
		document.frm.email.focus();
		return false;
	}
	if(!checkBlank(document.frm.email.value) && !checkEmail(document.frm.email.value))
	{
		alert("Please Enter Valid Email");
		document.frm.email.focus();
		return false;
	}
	if(checkBlank(document.frm.user.value))
	{
		alert("Please Enter Name");
		document.frm.user.focus();
		return false;
	}
	if(!checkBlank(document.frm.user.value) && !checkSpecialChars(document.frm.user.value))
	{
		alert("Please Enter Valid Name");
		document.frm.user.focus();
		return false;
	}
}
/////////////////////////End/////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
